package com.example.hibernate.program;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		try {
			// Employee employee = new Employee();
			// employee.setFirstName("Önder");
			// employee.setLastName("ŞAHİN");
			// employee.setEmail("crazyboy1234@gmail.com");
			// {
			// Vehicle vehicle = new Vehicle();
			// vehicle.setBrandName("Mercedes");
			// vehicle.setModel("C180");
			// //session.save(vehicle);
			// employee.setVehicle(vehicle);
			// }
			// session.save(employee);
			// Employee employee = (Employee) session.get(Employee.class, 2L);
			// System.out.println(employee);
			// System.out.println(employee.getVehicle());

			// Vehicle vehicle = (Vehicle) session.get(Vehicle.class, 1L);
			// System.out.println(vehicle);
			// System.out.println(vehicle.getEmployee());

			Employee employee = (Employee) session.get(Employee.class, 1L);
			session.delete(employee);
			transaction.commit();
		} catch (Exception e) {
			transaction.rollback();
		}
		session.close();
		sessionFactory.close();
	}
}
